home *** CD-ROM | disk | FTP | other *** search
/ TestDrive Windows 1993 Fall / TestDrive Windows 1993 Fall.iso / dbase / samples / movewin.prg < prev    next >
Encoding:
Text File  |  1993-03-09  |  3.9 KB  |  105 lines

  1. PROCEDURE MoveWin
  2. *--------------------------------------------------------------------
  3. * DESCRIPTION
  4. *   MoveWin demonstrates a technique that you can use to move
  5. *   a window around the screen using the mouse.
  6. *--------------------------------------------------------------------
  7.  
  8.   SET TRAP OFF
  9.   SET ESCAPE OFF
  10.   SET TALK OFF
  11.   SET CURSOR OFF
  12.   SET COLOR TO W+/B
  13.   SET STATUS OFF
  14.   nRow = 5                              && Top row for window
  15.   nCol = 10                             && Left column for window
  16.   nWidth = 40                           && Width of window
  17.   nHigh = 10                            && Height of window
  18.   DEFINE WINDOW Foo FROM nRow, nCol TO nRow + nHigh, nCol + nWidth NONE COLOR n/w
  19.   ACTIVATE WINDOW Foo
  20.   @ 0,0 TO nHigh,nWidth  DOUBLE COLOR w+/w
  21.  
  22.   *------------------------
  23.   *-- Close Icon for window
  24.   *------------------------
  25.   @ 0, 2 SAY "[ ]" COLOR w+/w
  26.   @ 0, 3 SAY CHR( 254 ) COLOR g+/w
  27.  
  28.   *--------------------------------
  29.   *-- Display the usage information
  30.   *--------------------------------
  31.   @ 1,1 SAY " Click on top border to start move,"
  32.   @ 2,1 SAY " then click to anchor the window."
  33.   @ 3,1 SAY " Click on close icon or press"
  34.   @ 4,1 SAY " Esc when done."
  35.  
  36.   nMess = 0
  37.   DO WHILE nMess <> 27                  && Loop until Esc or click on Icon
  38.  
  39.     DO MSDummy                          && Remove when LASTKEY() = -100
  40.                                         && is fully implimented
  41.     SET CONSOLE OFF
  42.     WAIT                                && Wait for a mouse click,
  43.     SET CONSOLE ON
  44.     nMess = LASTKEY()                   && Get the last key or mouse click
  45.     nMRow = MROW()                      && Capture the mouse row and column
  46.     nMCol = MCOL()
  47.     IF nMess <= -100                    && If a mouse click occured
  48.       IF nMRow = nRow                   && Check to see if its on the top row
  49.         IF nMCol >= nCol + 2 .AND. nMCol <= nCol + 4
  50.           nMess = 27                    && Click was on the Close Icon
  51.         ELSE                            && so, signal loop to exit
  52.           IF nMCol >= nCol .AND. nMCol <= nCol + nWidth
  53.             *-- Start the move window action
  54.             @ 0,0 TO nHigh,nWidth DOUBLE COLOR w+/w*
  55.             nDelX = nMRow
  56.             nDelY = nMCol
  57.             SET CONSOLE OFF
  58.             WAIT                        && Wait for the "Drop" click
  59.             SET CONSOLE ON
  60.             nMRow = MROW()              && Capture the Mouse row and
  61.             nMCol = MCOL()              && column for the new location
  62.             nDelX = nMRow - nDelX       && Determine the difference in the
  63.             nDelY = nMCol - nDelY       && cursor position for the move
  64.             lMoveOk = .T.               && Error flag for Move Window command
  65.             ON ERROR lMoveOk = .F.      && If an error occurs, set error flag
  66.             MOVE WINDOW Foo BY nDelX, nDelY
  67.             IF lMoveOk                  && If the move was Ok, update
  68.               nRow = nRow + nDelX       && the new top row and left
  69.               nCol = nCol + nDelY       && column coordinates for the window
  70.             ENDIF
  71.             *-- Redraw the natural border
  72.             @ 0,0 TO nHigh, nWidth DOUBLE COLOR w+/w
  73.             *-- Redisplay the Close Icon for window
  74.             @ 0, 2 SAY "[ ]" COLOR w+/w
  75.             @ 0, 3 SAY CHR( 254 ) COLOR g+/w
  76.           ENDIF
  77.         ENDIF
  78.       ENDIF
  79.     ENDIF
  80.   ENDDO
  81.  
  82.   RELEASE WINDOW FOO
  83.   SET CURSOR ON
  84.   SET TRAP ON
  85.   SET ESCAPE ON
  86.   SET TALK ON
  87.  
  88. RETURN
  89. *-- EOP: MoveWin
  90.  
  91.  
  92. PROCEDURE MSDummy
  93. *--------------------------------------------------------------------
  94. * DESCRIPTION
  95. *   Remove this procedure when LASTKEY() = -100 after a mouse click
  96. *   is implimented in dBASE.
  97. *--------------------------------------------------------------------
  98.   SET CONSOLE OFF
  99.   KEYBOARD "{Alt-1}"
  100.   WAIT
  101.   SET CONSOLE ON
  102. RETURN
  103. *-- MSDummy
  104.  
  105.